// 搬寝室
#include <iostream>
#include <algorithm>
#define INF 0x7fffffff
using namespace std;

long long weights[2001] = {0};
long long solutions[1001][2001] = {0};

int main()
{
    ios::sync_with_stdio(false);
    int n, k;
    long long count;
    while (cin >> n >> k)
    {
        for (int i = 1; i <= n; i++)
        {
            cin >> weights[i];
        }
        sort(weights + 1, weights + n + 1);
        for (int i = 1; i <= n; i++)
        {
            solutions[0][i] = 0;
            count++;
        }
        for (int i = 1; i <= k; i++)
        {
            for (int j = 2 * i; j <= n; j++)
            {
                if (j > 2 * i)
                {
                    solutions[i][j] = solutions[i][j - 1];
                    count --;
                }
                else
                {
                    count ++;
                    solutions[i][j] = INF;
                }
                if (solutions[i][j] > solutions[i - 1][j - 2] + ((weights[j] - weights[j - 1]) * (weights[j] - weights[j - 1])))
                {
                    solutions[i][j] = solutions[i - 1][j - 2] + ((weights[j] - weights[j - 1]) * (weights[j] - weights[j - 1]));
                    count ++;
                }
            }
        }
        cout << solutions[k][n] << endl;
    }
    return 0;
}